#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    pid_t pid;
    char *message;
    int n=4, exit_code;
    printf("fork program starting\n");
    pid = fork();
    switch(pid)
    {
        case -1:
            perror("fork failed");
            exit(1);
        case 0:
            message = "This is child";
            //n = 5;
            exit_code = 37;
            sleep(3);
            break;
        default:
            message = "This is parent";
            n = 3;
            exit_code = 0;
            break;
            
    }

    printf("m:%d  n:%d, %d", &message, n, &n);
   /* for(n; (*n) > 0; (*n)--) {
        puts(message);
        sleep(1);
    }*/
    if (pid != 0) {
        printf("pid:%d\n", pid);
        int stat_val;
        pid_t child_pid;
        child_pid = wait(&stat_val);
        printf("child has finished :PID = %d\n", child_pid);
        if(WIFEXITED(stat_val))
            printf("child exited with code %d\n", WEXITSTATUS(stat_val));
        else
            printf("child terminated abnormally\n");

    }

    exit(exit_code);
}

